home *** CD-ROM | disk | FTP | other *** search
- #include "Find_icon.h"
-
- /* Constants */
- enum
- {
- eDLOG_ID = 128,
-
- // dialog items
- eDoneButton = 1,
- eStartStopButton,
- eMaxSpeedCheckbox,
- eBig8Icon,
- eBig4Icon,
- eBigBWIcon,
- eSmall8Icon,
- eSmall4Icon,
- eSmallBWIcon,
- eFileName
- };
-
- /* Globals */
- FSSpec gTheFile;
- Boolean gAnimating = false;
- Boolean gMaxSpeed = false;
- Find_icon_UPP gFindIcon = NULL;
-
- /* Prototypes */
- void Initialize(void);
- void main(void);
-
- static void SetUserItemProc( DialogPtr dp, short item, UserItemUPP callback )
- {
- short iType;
- Rect iRect;
- Handle dummyH;
-
- GetDialogItem( dp, item, &iType, &dummyH, &iRect );
- SetDialogItem( dp, item, iType, (Handle)callback, &iRect );
- }
-
- static void InvalItem( DialogPtr dp, short item )
- {
- short iType;
- Rect iRect;
- Handle dummyH;
-
- GetDialogItem( dp, item, &iType, &dummyH, &iRect );
- InvalRect( &iRect );
- }
-
- static OSErr NextFile( short index )
- {
- CInfoPBRec pb;
- OSErr err;
-
- pb.hFileInfo.ioNamePtr = gTheFile.name;
- pb.hFileInfo.ioVRefNum = gTheFile.vRefNum;
- pb.hFileInfo.ioDirID = gTheFile.parID;
- pb.hFileInfo.ioFDirIndex = index;
- err = PBGetCatInfoSync( &pb );
- return err;
- }
-
- static pascal Boolean ModalFilterProc(DialogPtr theDialog, EventRecord *theEvent, short *itemHit)
- {
- ModalFilterUPP standardFilter;
- static unsigned long lastIncTime = 0;
- static long fileIndex = 0;
- OSErr err;
-
- GetStdFilterProc( &standardFilter );
-
- if ( gAnimating && (theEvent->what == nullEvent) )
- {
- if ( gMaxSpeed || (TickCount() - lastIncTime > 60) )
- {
- fileIndex += 1;
- err = NextFile( fileIndex );
- if (err == fnfErr)
- {
- fileIndex = 1;
- NextFile( fileIndex );
- }
- ParamText( gTheFile.name, NULL, NULL, NULL );
- InvalItem( theDialog, eFileName );
- InvalItem( theDialog, eBig8Icon );
- InvalItem( theDialog, eBig4Icon );
- InvalItem( theDialog, eBigBWIcon );
- InvalItem( theDialog, eSmall8Icon );
- InvalItem( theDialog, eSmall4Icon );
- InvalItem( theDialog, eSmallBWIcon );
- lastIncTime = TickCount();
- }
- }
-
- return CallModalFilterProc( standardFilter, theDialog, theEvent, itemHit );
- }
-
-
- static pascal void IconItemProc(WindowPtr theWindow, short itemNo)
- {
- short iType;
- Rect iRect;
- Handle dummyH;
- Handle suite;
- OSErr err;
- MetaSelectorValue selector;
-
- GetDialogItem( theWindow, itemNo, &iType, &dummyH, &iRect );
- switch( itemNo )
- {
- case eBig8Icon:
- case eSmall8Icon:
- selector = kSelectorAllAvailableData;
- break;
-
- case eBig4Icon:
- case eSmall4Icon:
- selector = kSelectorAll4BitData | kSelectorAll1BitData;
- break;
-
- case eBigBWIcon:
- case eSmallBWIcon:
- selector = kSelectorAll1BitData;
- break;
- }
-
- EraseRect( &iRect );
-
- err = CallFindIcon( gFindIcon, &gTheFile, selector, &suite );
- if (err == noErr)
- {
- PlotIconSuite( &iRect, kAlignNone, kTransformNone, suite );
- DisposeIconSuite( suite, true );
- }
- }
-
- //MW specified argument and return type.
- void main(void)
- {
- DialogPtr dp;
- short itemHit;
- ControlHandle maxSpeedCheckbox;
- short iType;
- Rect iRect;
- UserItemUPP iconItemUPP;
- ProcessSerialNumber myPSN = { kNoProcess, kCurrentProcess };
- ProcessInfoRec pInfo;
- Handle findIconProc;
- ModalFilterUPP myFilter;
-
- Initialize();
-
- findIconProc = GetResource( 'PROC', 128 );
- if (findIconProc == NULL)
- {
- return;
- }
- HLock( findIconProc );
- gFindIcon = (Find_icon_UPP) *findIconProc;
-
- dp = GetNewDialog( eDLOG_ID, NULL, (WindowPtr) -1L );
- SetPort( dp );
- SetDialogDefaultItem( dp, eDoneButton );
- ShowWindow( dp );
- GetDialogItem( dp, eMaxSpeedCheckbox, &iType, (Handle*) &maxSpeedCheckbox, &iRect );
-
- iconItemUPP = NewUserItemProc( IconItemProc );
- SetUserItemProc( dp, eBig8Icon, iconItemUPP );
- SetUserItemProc( dp, eBig4Icon, iconItemUPP );
- SetUserItemProc( dp, eBigBWIcon, iconItemUPP );
- SetUserItemProc( dp, eSmall8Icon, iconItemUPP );
- SetUserItemProc( dp, eSmall4Icon, iconItemUPP );
- SetUserItemProc( dp, eSmallBWIcon, iconItemUPP );
-
- myFilter = NewModalFilterProc( ModalFilterProc );
-
- pInfo.processInfoLength = sizeof(pInfo);
- pInfo.processName = NULL;
- pInfo.processAppSpec = &gTheFile;
- GetProcessInformation( &myPSN, &pInfo );
-
- ParamText( gTheFile.name, NULL, NULL, NULL );
-
- do {
- ModalDialog( myFilter, &itemHit );
- if (itemHit == eMaxSpeedCheckbox)
- {
- gMaxSpeed = !gMaxSpeed;
- SetControlValue( maxSpeedCheckbox, gMaxSpeed );
- }
- else if (itemHit == eStartStopButton)
- {
- gAnimating = !gAnimating;
- }
- } while (itemHit != eDoneButton);
-
- DisposeDialog( dp );
- }
-
- void Initialize(void)
- {
- /* Initialize all the needed managers. */
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- }
-
-
-